<template>
	<div>
		<el-dialog title="哺乳用药自定义" :visible.sync="dialogVisibleXiangHu" width="60%" :before-close="handleClose">
			<el-card>
				<el-row :gutter="15">
					<el-form label-width="80px">
						<el-col :span="12">
							<el-form-item label="生效范围">
								<el-checkbox-group v-model="sxfwVal">
									<el-checkbox v-for="item in sxfwCheckbox"
										:label="item.label"
										:key="item.value">
									</el-checkbox>
								</el-checkbox-group>
							</el-form-item>	
						</el-col>
						<el-col :span="12">
							<el-form-item label="警示级别">
								<el-select v-model="slCode" placeholder="请选择警示级别">
									<el-option
									  v-for="item in jsjbOptions"
									  :key="item.value"
									  :label="item.label"
									  :value="item.value">
									</el-option>
								</el-select>
							</el-form-item>	
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="警示信息">
								<el-input type="textarea" v-model="remark"></el-input>
							</el-form-item>
						</el-col>
					</el-form>
				</el-row>
				
				<div class="clear">
					<el-button type="success" class="fr" @click="onSubmit">保存</el-button>
				</div>
			</el-card>
			<el-card style="margin-top:10px">
				<Graytable :tHead="tHead" :tData="tData"  @operateClick="operateClick"></Graytable>
				<pagination
					:total="query.total"
					:page.sync="query.page"
					:limit.sync="query.limit"
					@pagination="getList"/>
			</el-card>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleXiangHu = false">关 闭</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		props:{
			dataObj:{
				required:true
			}
		},
		data () {
			return {
				query: {
				  total: 0,
				  page: 1,
				  limit: 10
				},
				slCode:"0",//警示级别value
				jsjbOptions:[
					{
					  value: '0',
					  label: '拦截'
					},
					{
					  value: '1',
					  label: '禁忌'
					},
					{
					  value: '2',
					  label: '不推荐'
					},
					{
					  value: '3',
					  label: '轻微'
					},
				],//警示级别options
				sxfwVal:[],//生效范围value
				sxfwCheckbox:[
					{
					  value: '1',
					  label: '急诊'
					},
					{
					  value: '2',
					  label: '门诊'
					},
					{
					  value: '3',
					  label: '住院'
					},
				],//生效范围checkbox
				dialogVisibleXiangHu:false,
				tHead:[
					{
						label:"操作",
						operate:["删除"],
						align:"center",
						width:"50px"
					},
					{
						prop:"warning",
						label:"警示"
					},
					{
						prop:"intercept",
						label:"拦截"
					},
					{
						prop:"effectiveRange",
						label:"生效范围"
					},
					{
						prop:"warningLights",
						label:"警示灯"
					},
					{
						prop:"warningLevel",
						label:"警示级别"
					},
					{
						prop:"warningInformation",
						label:"警示信息"
					},
					{
						prop:"operUser",
						label:"维护人员"
					},
					{
						prop:"date",
						label:"维护日期"
					},
				],
				tData:[],
				remark:"",
				nowData:{}
			}
		},
		watch:{
			dataObj(val){
				this.nowData=val;
				this.resetTData(true);
			}
		},
		methods:{
			async getList () {
				let res=await this.$custom.listBreastFeedingSelected({
					drugUniqueCode:this.nowData.drugUniqueCode,
					page:this.query.page,
					pageSize:this.query.limit
				})
				for(var i in res.rows){
					if(res.rows[i].warning == 0){
						res.rows[i].warning = "否";
					}else if(res.rows[i].warning == 1){
						res.rows[i].warning = "是";
					}
					
					if(res.rows[i].intercept == 0){
						res.rows[i].intercept = "否";
					}else if(res.rows[i].intercept == 1){
						res.rows[i].intercept = "是";
					}
					
					if(res.rows[i].warningLevel == 1){
						res.rows[i].warningLevel = '<span class="lanjie">拦截</span>';
					}else if(res.rows[i].warningLevel == 2){
						res.rows[i].warningLevel = '<span class="jinji">禁忌</span>';
					}else if(res.rows[i].warningLevel == 3){
						res.rows[i].warningLevel = '<span class="butuijian">不推荐</span>';
					}else if(res.rows[i].warningLevel == 4){
						res.rows[i].warningLevel = '<span class="qingwei">轻微</span>';
					}
					
					if(res.rows[i].effectiveRange == 1){
						res.rows[i].effectiveRange = '急诊';
					}else if(res.rows[i].effectiveRange == 2){
						res.rows[i].effectiveRange = '门诊';
					}else if(res.rows[i].effectiveRange == 3){
						res.rows[i].effectiveRange = '住院';
					}else if(res.rows[i].effectiveRange == 12){
						res.rows[i].effectiveRange = '急诊 门诊';
					}else if(res.rows[i].effectiveRange == 13){
						res.rows[i].effectiveRange = '急诊 住院';
					}else if(res.rows[i].effectiveRange == 23){
						res.rows[i].effectiveRange = '门诊 住院';
					}else if(res.rows[i].effectiveRange == 123){
						res.rows[i].effectiveRange = '急诊 门诊 住院';
					}
					
					res.rows[i].date = this.$rad.getdate(res.rows[i].date);
				}
				this.tData=res.rows;
				this.query.total=res.total;
			},
			show(){
				this.dialogVisibleXiangHu = true;
			},
			async onSubmit () {
				if(this.sxfwVal.length == 0){
					this.$message({
					  message: "请选择生效范围",
					  type:'error',
					  duration:1000
					});
					return;
				}
				if(!this.remark){
					this.$message({
					  message: "请输入警示信息",
					  type:'error',
					  duration:1000
					});
					return;
				}
				var sx1 = "",sx2 = "",sx3 = "";
				var sxfwVal = this.sxfwVal;
				for(var i in sxfwVal){
					if(sxfwVal[i].includes("急诊")){
						sx1 = 1;
					}
					if(sxfwVal[i].includes("门诊")){
						sx2 = 2;
					}
					if(sxfwVal[i].includes("住院")){
						sx3 = 3;
					}
				}
				let res=await this.$custom.listBreastFeedingSave({
					emergencyDepartment:sx1,
					outpatientService:sx2,
					InHospital:sx3,
					drugUniqueCode:this.nowData.drugUniqueCode,
					warningInformation:this.remark,
					warningLevel:this.slCode
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				this.resetTData();
			},
			resetTData(flag){
				this.sxfwVal=[];
				this.slCode="0";
				this.remark="";
				this.query={
					total:0,
					page:1,
					limit:10
				}
				this.tData=[];
				this.getList();
				if(!flag){
					this.$emit("changeFun")
				}
			},
			handleClose () {
				this.dialogVisibleXiangHu = false;
			},
			operateClick(item,row){
				this.$confirm('确定删除通用自定义?', '提示', {
					confirmButtonText: '确定删除',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.delFun(row);
				}).catch(() => {
				});
			},
			async delFun(row){
				let res=await this.$custom.listBreastFeedingDel({
					drugUniqueCode:this.nowData.drugUniqueCode,
					id:row.id
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				this.resetTData();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.el-card {
		margin-left: 3px;
	}

	.SearchT {
		display: flex;
		justify-content: flex-end;
		height: 40px;
		align-items: center;
		background-color: #e6edf3;
		font-size: 14px;
	}

	.tableLable {
		flex: 1;
		text-align: left;
		margin-left: 15px;
		letter-spacing: 2px;
		font-size: 14px;
		color: #32a6f3;
		font-weight: bold;
	}

	/* .exportBtn {
  margin-right: 23px;
}
.BatchDeleBtn {
  margin-right: 15px;
} */
	.tableStyle {
		width: 100%;
		height: 100%;
	}

	.card-table {
		width: 100%;
		height: 75%;
	}

	.block {
		text-align: center;
		margin-top: 12px;
		margin-bottom: 12px;
	}

	.Btn {
		display: flex;
		flex: 1;
		flex-wrap: nowrap;
	}

	.dialogFirstRow>>>.el-input {
		width: 70px;
		margin-right: 10px;
	}

	.el-form-item.s_selectbox>>>.el-form-item__content {
		width: 80%;
	}
	/* .demo-form-inline>>>.el-form-item {
		margin-bottom: 0px;
	} */
</style>
